package c.c.b.b.f;

import android.net.TrafficStats;
import android.os.Process;
import android.os.SystemClock;
import c.c.b.b.e.f;
import c.c.b.b.h.a;
import c.c.b.b.i.b;
import c.c.b.b.i.c;
import c.c.b.b.i.d;
import java.util.concurrent.BlockingQueue;

/* compiled from: NetworkDispatcher */
public class l extends Thread {
    public final BlockingQueue<c<?>> a;
    public final c b;
    public final b c;
    public final d d;
    public volatile boolean e = false;

    public l(BlockingQueue<c<?>> blockingQueue, c cVar, b bVar, d dVar) {
        this.a = blockingQueue;
        this.b = cVar;
        this.c = bVar;
        this.d = dVar;
    }

    public final void a() throws InterruptedException {
        a e;
        c cVar = (c) this.a.take();
        SystemClock.elapsedRealtime();
        cVar.a(3);
        try {
            cVar.addMarker("network-queue-take");
            if (cVar.isCanceled()) {
                cVar.a("network-discard-cancelled");
                cVar.e();
            } else {
                TrafficStats.setThreadStatsTag(cVar.getTrafficStatsTag());
                m a = ((d) this.b).a(cVar);
                cVar.setNetDuration(a.f);
                cVar.addMarker("network-http-complete");
                if (a.e && cVar.hasHadResponseDelivered()) {
                    cVar.a("not-modified");
                    cVar.e();
                } else {
                    p a2 = cVar.a(a);
                    cVar.setNetDuration(a.f);
                    cVar.addMarker("network-parse-complete");
                    if (cVar.shouldCache() && a2.b != null) {
                        ((j) this.c).h(cVar.getCacheKey(), a2.b);
                        cVar.addMarker("network-cache-written");
                    }
                    cVar.markDelivered();
                    k kVar = (k) this.d;
                    kVar.a(cVar, a2, null);
                    c.c.b.b.e.c cVar2 = kVar.c;
                    if (cVar2 != null) {
                        ((f) cVar2).c(cVar, a2);
                    }
                    cVar.b(a2);
                }
            }
        } catch (a e2) {
            SystemClock.elapsedRealtime();
            ((k) this.d).b(cVar, cVar.a(e2));
            cVar.e();
        } catch (Exception e3) {
            q.b(e3, "Unhandled exception %s", e3.toString());
            e2 = new a(e3);
            SystemClock.elapsedRealtime();
            ((k) this.d).b(cVar, e2);
            cVar.e();
        } catch (Throwable th) {
            cVar.a(4);
        }
        cVar.a(4);
    }

    public void run() {
        Process.setThreadPriority(10);
        while (true) {
            try {
                a();
            } catch (InterruptedException unused) {
                if (this.e) {
                    Thread.currentThread().interrupt();
                    return;
                } else {
                    q.d("Ignoring spurious interrupt of NetworkDispatcher thread; use quit() to terminate it", new Object[0]);
                }
            }
        }
    }
}
